﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Column : DLL.MyAdminPage
{
	protected void Page_Load(object sender, EventArgs e)
	{
		string strColumnIDs;

		strColumnIDs = Session["ColumnIDs"].ToString();

		SetColumnsTree(strColumnIDs);
	}

	#region 用TreeView显示栏目
	private void SetColumnsTree(string strColumnIDs)
	{
		DLL.Column.Component clsColumnComp = new DLL.Column.Component(Page);
		List<DLL.Column.Entity> listFirstColumns;		// 一级栏目

		listFirstColumns = clsColumnComp.QueryAdminFirstByRight(strColumnIDs);		// 根据用户权限查询所有一级栏目

		TreeColumns.Nodes.Clear();		// 清除Tree

		for (int i = 0; i < listFirstColumns.Count; i++)
		{

			TreeNode treeNode;

			treeNode = new TreeNode();

			treeNode.Text = listFirstColumns[i].ColumnName;
			if (listFirstColumns[i].Link != "")
			{
				treeNode.NavigateUrl = listFirstColumns[i].Link + "?ColumnID=" + listFirstColumns[i].ID;
			}
			treeNode.SelectAction = TreeNodeSelectAction.Expand;
			treeNode.Target = "Content";

			AddTree(listFirstColumns[i].ID, treeNode, strColumnIDs);

			TreeColumns.Nodes.Add(treeNode);
		}

		TreeColumns.CollapseAll();

		//TreeNode tNode;

		//tNode = new TreeNode();
		//tNode.Text = "退出";
		//tNode.NavigateUrl = "Login.aspx";
		//tNode.Target = "_top";
		//TreeColumns.Nodes.Add(tNode);
	}

	private void AddTree(int nFatherID, TreeNode treeNodeFatherNode, string strColumnIDs)
	{
		List<DLL.Column.Entity> list;
		List<DLL.Column.Entity> listChildColumns;
		DLL.Column.Component clsColumnComp = new DLL.Column.Component(Page);

		list = clsColumnComp.QueryAdminByParentRight(nFatherID, strColumnIDs);

		for (int i = 0; i < list.Count; i++)
		{
			TreeNode treeNode;

			treeNode = new TreeNode();

			treeNode.Text = list[i].ColumnName;
			if (list[i].Link != "")
			{
				treeNode.NavigateUrl = list[i].Link + "?ColumnID=" + list[i].ID;
			}
			treeNode.SelectAction = TreeNodeSelectAction.Expand;
			treeNode.Target = "Content";

			listChildColumns = clsColumnComp.QueryAdminByParentRight(list[i].ID, strColumnIDs);
			if (listChildColumns.Count > 0)
			{
				AddTree(list[i].ID, treeNode, strColumnIDs);
			}

			treeNodeFatherNode.ChildNodes.Add(treeNode);
		}
	}
	#endregion
}